import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
  'user',
  () => {
    const user = ref()

    const setUser = (val: unknown) => {
      user.value = val
    }

    const clearUser = () => {
      user.value = undefined
    }

    return { user, setUser, clearUser }
  },
  {
    persist: {
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, value) {
          uni.setStorageSync(key, value)
        },
      },
    },
  },
)
